<template>
  <div>
    <home-header></home-header>
    <search-box></search-box>
    <div id="shoplist-title" class="shoplist-title" >
      推荐商家
    </div>
    <div style="position: sticky;top: 50px;z-index: 100;">
      <restaurant-filter></restaurant-filter>
    </div>
    <div>
      <div class="app-3GmD-_1" style="padding-bottom: 0px;">
        <div style="display: none">
        </div>
        <div class="shop-3SsDF">
          <div></div>
          <div class="shop-3XmEa">
            <div v-for="rest in restaurants">
              <restaurant-list :rest="rest.restaurant"></restaurant-list>
            </div>
            <infinite-loading @infinite="_loadNewData">
              <span slot="no-more" style="color: #ccc;">
                没有更多数据了...
              </span>
            </infinite-loading>
          </div>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
  import {mapGetters} from 'vuex'
  import InfiniteLoading from 'vue-infinite-loading'

  import {getNearRestaurantsInfo} from "api/restaurants/near-restaurants-info";

  import myheader from 'components/home/home-header'
  import restaurantList from "components/common/restaurant-list"
  import searchBox from 'components/home/search-box'
  import restaurantFilter from "components/common/restaurant-filter"

  export default {
      name: "nearRestaurants",
      data () {
        return {
          msg: 'Welcome to Your Vue.js App',
          restaurants: [],
          offset: 0
        }
      },
      components:{
        'restaurant-list':restaurantList,
        'home-header':myheader,
        'search-box':searchBox,
        InfiniteLoading,
        'restaurant-filter':restaurantFilter
      },
      computed: {
        ...mapGetters({
          addressInfo:'getAddressInfo',
          orderBy:'getOrderBy'
        })
      },
      created(){
        this._loadNearRestaurants();
      },
      watch:{
        orderBy(){
          this._loadNearRestaurants();
        }
      },
      methods:{
        _loadNearRestaurants(){
          getNearRestaurantsInfo(this.$http,this.addressInfo.latitude,this.addressInfo.longitude,this.offset,this.orderBy).then(
            res => {
              console.log(res.data);
              this.restaurants = res.data.items;
              this.offset += 8;
            },
            res => {
              console.log("load near restaurants data fail");
            }
          )
        },
        _loadNewData($state){
          console.log(this.offset);
          getNearRestaurantsInfo(this.$http,this.addressInfo.latitude,this.addressInfo.longitude,this.offset,this.orderBy).then( (data)=>{

            if(data.data.items.length > 0){
              this.restaurants = this.restaurants.concat(data.data.items);
              console.log(this.restaurants);
              this.offset +=8;
              $state.loaded();
            }else{
              $state.complete();
            }
          })
        }
      }

    }
</script>

<style scoped>
  html {
    display: block;
  }
  Style Attribute {
    font-size: 36px;
  }
  html {
    box-sizing: border-box;
    background-color: #f5f5f5;
    color: #333;
    font-family: PingFang SC,Helvetica Neue,Arial,sans-serif;
    line-height: 1.2;
    -webkit-user-select: none;
    user-select: none;
    -webkit-font-smoothing: antialiased;
    touch-action: manipulation;
    -webkit-text-size-adjust: none;
    text-size-adjust: none;
  }
  .app-21LS3_1 {
    width: .933333rem;
    width: 9.333333vw;
    height: .933333rem;
    height: 9.333333vw;
    fill: #999;
    padding: .133333rem .133333rem .133333rem 0;
    padding: 1.333333vw 1.333333vw 1.333333vw 0;
  }
  *, :after, :before {
    box-sizing: inherit;
    -webkit-tap-highlight-color: transparent;
  }
  svg:not(:root), symbol, image, marker, pattern, foreignObject {
    overflow: hidden;
  }
  *, :after, :before {
    box-sizing: inherit;
    -webkit-tap-highlight-color: transparent;
  }

  element.style {
  }
  .app-iYo7n_1 {
    -webkit-flex-grow: 1;
    flex-grow: 1;
    padding: .293333rem .293333rem .293333rem 0;
    padding: 2.933333vw 2.933333vw 2.933333vw 0;
    margin-left: .293333rem;
    margin-left: 2.933333vw;
    background-color: #fff;
    z-index: 101;
  }
  .app-3rytA_1, .app-iYo7n_1 {
    display: -webkit-flex;
    display: flex;
    position: relative;
  }
  *, :after, :before {
    box-sizing: inherit;
    -webkit-tap-highlight-color: transparent;
  }
  user agent stylesheet
  form {
    display: block;
    margin-top: 0em;
  }
  *, :after, :before {
    box-sizing: inherit;
    -webkit-tap-highlight-color: transparent;
  }
  *, :after, :before {
    box-sizing: inherit;
    -webkit-tap-highlight-color: transparent;
  }
  Style Attribute {
    font-size: 36px;
  }
  *, :after, :before {
    box-sizing: inherit;
    -webkit-tap-highlight-color: transparent;
  }
  Style Attribute {
    font-size: 32px;
  }

  *, :after, :before {
    box-sizing: inherit;
    -webkit-tap-highlight-color: transparent;
  }
  *, :after, :before {
    box-sizing: inherit;
    -webkit-tap-highlight-color: transparent;
  }
  *, :after, :before {
    box-sizing: inherit;
    -webkit-tap-highlight-color: transparent;
  }

  .app-11zxJ_1 {
    -webkit-flex-grow: 1;
    flex-grow: 1;
    border-radius: .026667rem;
    border-radius: .266667vw;
    -webkit-appearance: none;
    background-color: #f8f8f8;
    padding: .173333rem .4rem .173333rem .88rem;
    padding: 1.733333vw 4vw 1.733333vw 8.8vw;
    font-size: .346667rem;
    color: #666;
  }
  button, input {
    outline: none;
    border: none;
    font-size: inherit;
    font-family: inherit;
  }
  button, input, select, textarea {
    outline: none;
    border: none;
    font-size: inherit;
    font-family: inherit;
  }
  *, :after, :before {
    box-sizing: inherit;
    -webkit-tap-highlight-color: transparent;
  }
  user agent stylesheet
  input[type="search" i] {
    padding: 1px;
  }
  user agent stylesheet
  input[type="search" i] {
    -webkit-appearance: searchfield;
    box-sizing: border-box;
  }
  user agent stylesheet
  input {
    -webkit-appearance: textfield;
    background-color: white;
    -webkit-rtl-ordering: logical;
    cursor: text;
    padding: 1px;
    border-width: 2px;
    border-style: inset;
    border-color: initial;
    border-image: initial;
  }
  user agent stylesheet
  input, textarea, select, button {
    text-rendering: auto;
    color: initial;
    letter-spacing: normal;
    word-spacing: normal;
    text-transform: none;
    text-indent: 0px;
    text-shadow: none;
    display: inline-block;
    text-align: start;
    margin: 0em;
    font: 400 13.3333px Arial;
  }
  user agent stylesheet
  input, textarea, select, button, meter, progress {
    -webkit-writing-mode: horizontal-tb !important;
  }
  /*<商品展示样式*/
  .app-3GmD-_1 {
    height: calc(100vh - 1.36rem);
    height: calc(100vh - 13.6vw);
  }
  .shop-3SsDF {
    height: 100%;
    display: -webkit-flex;
    display: flex;
    -webkit-flex-direction: column;
    flex-direction: column;
  }
  .shop-3XmEa {
    -webkit-flex: 1;
    flex: 1;
    overflow-y: scroll;
    -webkit-overflow-scrolling: touch;
  }
  .shoplist, .shoplist-title {
    background-color: #fff;
  }
  .shoplist-title {
    display: -webkit-box;
    display: -webkit-flex;
    display: -ms-flexbox;
    display: flex;
    -webkit-box-align: center;
    -webkit-align-items: center;
    -ms-flex-align: center;
    align-items: center;
    -webkit-box-pack: center;
    -webkit-justify-content: center;
    -ms-flex-pack: center;
    justify-content: center;
    height: .96rem;
    height: 9.6vw;
    font-size: .7rem;
    color: #000;
  }
  .shoplist-title:after, .shoplist-title:before {
    display: block;
    content: "";
    width: .533333rem;
    width: 5.333333vw;
    height: .026667rem;
    height: .266667vw;
    background-color: #999;
  }
  .shoplist-title:before {
    margin-right: .346667rem;
    margin-right: 3.466667vw;
  }
  .shoplist-title:after {
    margin-left: .346667rem;
    margin-left: 3.466667vw;
  }

</style>
